package com.cloud.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class TranForFrom {
    public static void main(String[] args) {
        try {
            FileOutputStream fileOutputStream = new FileOutputStream("pickup.png");
            FileInputStream fileInputStream = new FileInputStream("捡起瓜子.png");

            // 创建通道
            FileChannel inChannel = fileInputStream.getChannel();
            FileChannel outChannel = fileOutputStream.getChannel();

            // 使用该方法完成拷贝
            outChannel.transferFrom(inChannel,0,inChannel.size());
            // 关闭相关的通道和流
            fileInputStream.close();
            fileOutputStream.close();
            inChannel.close();
            outChannel.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
